import 'package:flutter/material.dart';
import 'package:m6/Public/customer_widget/customer_widget.dart';
import 'package:m6/Public/customer_widget/dashed_line.dart';

class ProductDetail extends StatefulWidget {
  const ProductDetail({super.key});

  @override
  State<ProductDetail> createState() => _ProductDetailState();
}

class _ProductDetailState extends State<ProductDetail> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: M6AppBar("产品详情"),
        body: SafeArea(
            bottom: false,
            maintainBottomViewPadding: false,
            child: Stack(
              children: [
                Container(),
                Positioned(
                  child: Container(
                    width: double.infinity,
                    decoration: BoxDecoration(color: MainColor()),
                    child: const SizedBox(
                      width: double.infinity,
                      height: 70,
                    ),
                  ),
                ),
                Positioned(
                  left: 8,
                  right: 8,
                  bottom: 0,
                  top: 0,
                  child: ListView(
                    children: [
                      productInfo(),
                      certificationCard(),
                      tips(),
                    ],
                  ),
                ),
                Positioned(bottom: 0, right: 0, left: 0, child: applyButton())
              ],
            )));
  }

  Widget productInfo() {
    return Card(
        shadowColor: Colors.white,
        margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
        color: Colors.white,
        child: Container(
          padding: EdgeInsets.only(left: 16, right: 16),
          child: Column(
            children: [
              Container(
                padding: const EdgeInsets.only(top: 20),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    const SizedBox(
                      width: 24,
                      height: 24,
                      child: Icon(
                        Icons.food_bank_rounded,
                        color: Colors.red,
                      ),
                    ),
                    Text(
                      "Go Money",
                      style: TextStyle(color: Color333333(), fontSize: 14),
                    )
                  ],
                ),
              ),
              rowText("借款金额", "＄6.000", false),
              rowText("借款天数", "91 días", false),
              line(),
              rowText("实际到账", "＄5.800", true),
              rowText("到期应还", "＄6.200", true),
              rowText("利息+服务费", "＄400", true),
            ],
          ),
        ));
  }

  Widget rowText(String title, String detail, bool isSub) {
    return Container(
        margin: EdgeInsets.only(bottom: 8),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              title,
              style: TextStyle(
                color: isSub == false ? Color333333() : Color666666(),
                fontSize: 14,
                fontWeight: isSub == false ? FontWeight.w600 : FontWeight.w300,
              ),
            ),
            Text(
              detail,
              style: TextStyle(
                color: Color333333(),
                fontSize: isSub == false ? 20 : 14,
                fontWeight: isSub == false ? FontWeight.bold : FontWeight.w500,
              ),
            ),
          ],
        ));
  }

  Widget line() {
    return Container(
        height: 1,
        margin: const EdgeInsets.only(top: 12, bottom: 20),
        // child: Dashlin,
        child: DashedLine(
          axis: Axis.horizontal,
          dashedWidth: 4,
          dashedHeight: 1,
          color: ColorCCCCCC(),
          count: 50,
        ));
  }

  Widget certificationCard() {
    return Card(
        shadowColor: Colors.white,
        margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
        color: Colors.white,
        child: Container(
          padding: EdgeInsets.only(left: 16, right: 16),
          child: Column(
            children: [
              Container(
                padding: const EdgeInsets.only(top: 20),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    Text(
                      "认证材料",
                      style: TextStyle(
                          color: Color333333(),
                          fontSize: 16,
                          fontWeight: FontWeight.w600),
                    )
                  ],
                ),
              ),
              certificationButton(),
              certificationButton(),
              certificationButton(),
              certificationButton()
            ],
          ),
        ));
  }

  Widget certificationButton() {
    return Row(
      children: [
        Expanded(
            child: ListTile(
          contentPadding: EdgeInsets.only(left: 0, top: 0, bottom: 0),
          horizontalTitleGap: -2,
          visualDensity: VisualDensity.compact,
          leading: Icon(
            Icons.expand_circle_down_rounded,
            color: MainColor(),
            size: 32,
          ),
          title: Text(
            "Datos personales",
            style: TextStyle(
                color: Color333333(),
                fontWeight: FontWeight.w500,
                fontSize: 14),
          ),
          subtitle: Text(
            "Verificado",
            style: TextStyle(
                color: Color999999(),
                fontWeight: FontWeight.w500,
                fontSize: 11),
          ),
          trailing: const Icon(
            Icons.chevron_right,
            color: Color(0xFFBEBEBE),
          ),
        )),
      ],
    );
  }

  Widget tips() {
    return Container(
      padding: const EdgeInsets.only(left: 10, right: 10, top: 20, bottom: 20),
      child: Text(
        "我们不参与借款流程，实际审核及放款均由资金方操作",
        style: TextStyle(color: Color666666(), fontSize: 12),
      ),
    );
  }

  Widget applyButton() {
    return ElevatedButton(
        style: ButtonStyle(
            shape: MaterialStateProperty.all(
                BeveledRectangleBorder(borderRadius: BorderRadius.circular(0))),
            backgroundColor: MaterialStatePropertyAll<Color>(MainColor())),
        onPressed: () {},
        child: Text(
          "立即申请",
          style: TextStyle(color: Colors.white, fontSize: 16),
        ));
  }
}
